package com.zbs.framework.core.user.action;


import com.zbs.framework.common.utils.ResultData;
import com.zbs.framework.common.utils.ResultUtil;
import com.zbs.framework.dao.user.service.UserManageService;
import com.zbs.framework.swagger.annotations.ApiOperation;
import com.zbs.framework.swagger.annotations.ApiParam;
import com.zbs.framework.swagger.annotations.ApiTags;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@ApiTags(value = "用户管理心", group = "UIM")
@RestController
@RequestMapping("/user/manage")
public class UserManageController {

    @Autowired
    private UserManageService userManageService;

    /**
     * 修改用户密码
     * @param userId
     * @param pwd
     * @return
     */
    @ApiOperation("修改用户密码")
    @PostMapping("/forceChangePwd")
    @PreAuthorize("hasAuthority('sys::changeUserPwd')")
    public ResultData<?> forceChangePwd(@ApiParam("用户id") Long userId,@ApiParam("用户密码") String pwd) {
        userManageService.forceChangePwd(userId, pwd);
        return ResultUtil.ok();
    }

    /**
     * 设置用户启用/禁用状态
     * @param userId
     * @param enabled
     * @return
     */
    @ApiOperation("设置用户启用/禁用状态")
    @PostMapping("/setUserEnabled")
    @PreAuthorize("hasAuthority('sys::setUserEnabled')")
    public ResultData<?> setUserEnabled(@ApiParam("用户id") Long userId,@ApiParam("启用 1 禁用 0") Integer enabled) {
        userManageService.setUserEnabled(userId, enabled);
        return ResultUtil.ok();
    }
}
